// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
#pragma once
#include "ILocationService.h"
#include "LocatorAgent.h"

namespace Weathr
{
    [Windows::UI::Xaml::Data::Bindable]
    [Windows::Foundation::Metadata::WebHostHidden]
    public ref class Pin sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
    {
    public:
        virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;

        property double X
        {
            double get() { return m_x; }
            void set(double value)
            {
                if (value != m_x)
                {
                    m_x = value; OnPropertyChanged("X");
                }
            }
        }
        property double Y
        {
            double get() { return m_y; }
            void set(double value)
            {
                if (value != m_y)
                {
                    m_y = value; OnPropertyChanged("Y");
                }
            }
        }

        property bool IsVisible
        {
            bool get() { return m_visible; }
            void set(bool value)
            {
                if (value != m_visible)
                {
                    m_visible = value; OnPropertyChanged("IsVisible");
                }
            }
        }

        property bool IsValid
        {
            bool get() { return m_valid; }
            void set(bool value)
            {
                if (value != m_valid)
                {
                    m_valid = value; OnPropertyChanged("IsValid");
                }
            }
        }

        property Platform::String^ DisplayName
        {
            Platform::String^ get() { return m_displayName; }
            void set(Platform::String^ value)
            {
                if (value != m_displayName)
                {
                    m_displayName = value; OnPropertyChanged("DisplayName");
                }
            }
        }

        property bool IsPressed
        {
            bool get() { return m_pressed; }
            void set(bool value)
            {
                if (value != m_pressed)
                {
                    m_pressed = value; OnPropertyChanged("IsPressed");
                }
            }
        }
    internal:
        explicit Pin(std::shared_ptr<Web::ILocationService> locationService) : m_locatorAgent(locationService), m_x(0.0), m_y(0.0), m_visible(false), m_valid(false), m_pressed(false)
        {
            m_current = this;
        }

        property bool IsDirty;
        property double Width;
        property double Height;

        static property Pin^ Current
        {
            Pin^ get() { return m_current; }
        }

        LocatorAgent& GetLocatorAgent() { return m_locatorAgent; }

        property std::shared_ptr<Web::Location> Location;

    private:
        static Pin^ m_current;
        Platform::String^ m_displayName;
        LocatorAgent m_locatorAgent;
        double m_x;
        double m_y;
        bool m_visible;
        bool m_valid;
        bool m_pressed;

        inline void OnPropertyChanged(Platform::String^ propertyName)
        {
            PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(propertyName));
        }
    };
}